<template>
  <div>
    <el-dialog
      v-model="editVisible"
      width="70%"
      top="10vh"
      :close-on-click-modal="false"
      @close="handleclose"
    >
      <el-form>
        <el-form-item>
          <div class="container">
            <el-table
              :data="tableData"
              border
              class="table"
              style="width: 90%"
              ref="multipleTable"
              header-cell-class-name="table-header"
              @selection-change="handleSelectionChange"
            >
              <el-table-column type="selection" label="全选" width="55">
              </el-table-column>

              <el-table-column
                prop="principalPeople"
                label="持有者"
              ></el-table-column>
              <el-table-column
                prop="serialNumber"
                label="编号"
              ></el-table-column>
              <el-table-column
                prop="location"
                label="项目地址"
              ></el-table-column>
              <el-table-column
                prop="area"
                label="项目面积（亩）"
              ></el-table-column>
              <el-table-column prop="monitorCarbonReduction" label="碳排放量">
                <template #default="scope">
                  {{
                    Number(scope.row.monitorCarbonReduction) -
                    Number(scope.row.alreadyUsedCarbon)
                  }}
                </template></el-table-column
              >
              <el-table-column
                prop="recordNumber"
                label="备案号"
              ></el-table-column>
            </el-table>
            <!-- <div class="pagination">
              <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page="seachfrom.pageNum"
                :page-size="seachfrom.pageSize"
                :total="pageTotal"
                @current-change="handlePageChange"
              ></el-pagination>
            </div> -->
            <div class="btn_b">
              <el-button @click="handleclose" class="icon-search1"
                >取消</el-button
              >
              <el-button
                type="primary"
                class="icon-search"
                @click="handleSaveEdit"
                >确定</el-button
              >
            </div>
          </div>
        </el-form-item>
      </el-form>
      <template #footer> </template>
    </el-dialog>
  </div>
</template>
<script>
import { ref, reactive } from "vue";
import api from "../api/api";
import { ElMessage, ElMessageBox } from "element-plus";
export default {
  components: {},
  setup(props, context) {
    console.log(context);
    // 参考图片
    const editVisible = ref(context.attrs.editVisible);
    const radioValue = ref(context.attrs.radioValue);
    const handleclose = () => {
      editVisible.value = false;
      context.emit("handleclose", editVisible.value);
    };
    const seachfrom = reactive({
      certificateNumber: null,
      registerNumber: null,
      woodlandUsePeople: null,
      woodlandRightPeople: null,
      pageNum: 1,
      pageSize: 8,
    });
    const tableData = ref([]);
    const pageTotal = ref(0);
    const SelectList = ref([]);
    // 获取表格数据
    const getData = () => {
      api
        .getListAPI("carbon/client/carbon/getTradeCarbon", {})
        .then((res) => {
          if (res.data.code == 1) {
            for (var i = 0; i < res.data.data.length; i++) {
              res.data.data[i].checked = false;
            }
            tableData.value = res.data.data;
            pageTotal.value = res.data.data.total || 0;
            console.log(res);
          } else {
            ElMessage.error(res.data.message);
          }
          //数据处理
        })
        .catch((err) => {
          console.log(err);
        });
    };
    getData();
    // 查询操作
    const handleSearch = () => {
      seachfrom.pageNum = 1;
      getData();
    };
    const emptySearch = () => {
      seachfrom.pageNum = 1;
      seachfrom.registerNumber = null;
      seachfrom.certificateNumber = null;
      seachfrom.woodlandRightPeople = null;
    };
    const handleSelect = (res) => {
      radioValue.value = res;
    };
    const handleSaveEdit = () => {
      if (selectList.value.length == 0) {
        ElMessage.error("请选择碳票");
        return;
      }
      context.emit("handleSaveEdit", selectList.value);
    };
    const selectList = ref([]);
    const handleSelectionChange = (arr) => {
      selectList.value = arr;
    };
    return {
      radioValue,
      editVisible,
      tableData,
      seachfrom,
      pageTotal,
      SelectList,
      handleclose,
      handleSearch,
      emptySearch,
      handleSelect,
      handleSaveEdit,
      handleSelectionChange,
    };
  },
};
</script>

<style lang="less" scoped>
@import "../assets/css/common.css";
&:deep(.el-dialog) {
  background: none;
  box-shadow: none;
}
&:deep(.el-dialog__headerbtn .el-dialog__close) {
  color: #909399;
  background: #fff;
  width: 30px;
  height: 30px;
  border-radius: 360px;
  font-size: 30px;
}
&:deep(.el-form-item__content) {
  text-align: center;
}
&:deep(.el-input__inner) {
  width: 150px !important;
}
.btn_b {
  padding: 30px;
}
</style>
